﻿using System;

namespace ZYCommon
{
    

    public class SEQCreator
    {
        private int[] intCharIndexs = null;
        private int intFixLength = 0;
        private int intSEQStep = 1;
        private string strSEQ = null;
        private string strSEQChars = "0123456789";

        public string Create()
        {
            IntPtr ptr;
            char[] chArray = this.strSEQ.ToCharArray();
            this.intCharIndexs[(int) (ptr = (IntPtr) (this.intCharIndexs.Length - 1))] = this.intCharIndexs[(int) ptr] + this.intSEQStep;
            for (int i = this.intCharIndexs.Length - 1; i > 0; i--)
            {
                int[] numArray2;
                IntPtr ptr2;
                IntPtr ptr3;
                if (this.intCharIndexs[i] < this.strSEQChars.Length)
                {
                    break;
                }
                (numArray2 = this.intCharIndexs)[(int) (ptr2 = (IntPtr) i)] = numArray2[(int) ptr2] % this.strSEQChars.Length;
                if (this.intCharIndexs[i - 1] < 0)
                {
                    break;
                }
                this.intCharIndexs[(int) (ptr3 = (IntPtr) (i - 1))] = this.intCharIndexs[(int) ptr3] + 1;
            }
            for (int j = this.intCharIndexs.Length - 1; j > 0; j--)
            {
                if (this.intCharIndexs[j] >= 0)
                {
                    chArray[j] = this.strSEQChars[this.intCharIndexs[j]];
                }
            }
            this.strSEQ = new string(chArray);
            if (this.intFixLength > 0)
            {
                if (this.strSEQ == null)
                {
                    this.strSEQ = new string(this.strSEQChars[0], this.intFixLength);
                }
                else if (this.strSEQ.Length != this.intFixLength)
                {
                    this.strSEQ = this.strSEQ.PadRight(this.intFixLength, this.strSEQChars[0]);
                }
            }
            return this.strSEQ;
        }

        private void ResetCharIndexs()
        {
            if (this.intFixLength > 0)
            {
                if (this.strSEQ == null)
                {
                    this.strSEQ = new string(this.strSEQChars[0], this.intFixLength);
                }
                else if (this.strSEQ.Length != this.intFixLength)
                {
                    this.strSEQ = this.strSEQ.PadRight(this.intFixLength, this.strSEQChars[0]);
                }
            }
            this.intCharIndexs = new int[this.strSEQ.Length];
            for (int i = 0; i < this.strSEQ.Length; i++)
            {
                this.intCharIndexs[i] = this.strSEQChars.IndexOf(this.strSEQ[i]);
            }
        }

        public int FixLength
        {
            get
            {
                return this.intFixLength;
            }
            set
            {
                this.intFixLength = value;
                this.ResetCharIndexs();
            }
        }

        public string SEQ
        {
            get
            {
                return this.strSEQ;
            }
            set
            {
                this.strSEQ = value;
                this.ResetCharIndexs();
            }
        }

        public string SEQChars
        {
            get
            {
                return this.strSEQChars;
            }
            set
            {
                this.strSEQChars = value;
                this.ResetCharIndexs();
            }
        }

        public int SEQStep
        {
            get
            {
                return this.intSEQStep;
            }
            set
            {
                this.intSEQStep = value;
            }
        }
    }
}

